<template>
	<view class="userinfo">
		<view class="box">
			<view class="box-item">
				<text class="tit">头像</text>
				<button class="avatar-wrapper" open-type="chooseAvatar" @chooseavatar="onChooseAvatar">
					<image class="avatar" :src="avatarUrl"></image>
				</button>
			</view>
			<view class="box-item">
				<text class="tit">昵称</text>
				<input type="nickname" class="nickname" placeholder="请输入昵称" v-model="nickName" />
			</view>
		</view>
	
		<view class="tips">昵称限2-32个字符，一个汉字为2个字符</view>
		<button class="btn" type="primary" @click="submit">确认</button>
	</view>
</template>

<script>
	'use strict';
	var app = getApp();
	var https_1 = require('api/https.js');
	const defaultAvatarUrl = 'https://mmbiz.qpic.cn/mmbiz/icTdbqWNOwNRna42FI242Lcia07jQodd2FJGIYQfG0LAJGFxM4FbnQP6yfMxBgJ0F3YRqJCJ1aPAK2dQagdusBZg/0'
	
	export default {
		components: {},
		data() {
			return {
				avatarUrl: defaultAvatarUrl,
				nickName: ''
			};
		},
		/**
		 * 生命周期函数--监听页面加载
		 */
		onLoad: function() {
			
		},
		/**
		 * 生命周期函数--监听页面显示
		 */
		onShow: function() {
			
		},
		methods: {
			onChooseAvatar(e) {
			  this.avatarUrl = e.detail.avatarUrl
			},
			submit() {
				let prve = getCurrentPages();
				let current = prve[prve.length - 2];
				
				current.userInfo = Object.assign({}, {
					nickName: this.nickName,
					avatarUrl: this.avatarUrl
				});
				
				uni.navigateBack()
			}
		}
	};
</script>
<style lang="less" scoped>
	@import url("./userInfo.less");
</style>